Imports System.Data.SqlClient
Imports Conexao
Public Class GTransacional
    Private objConexao As IDbConnection
    Private objTransacao As IDbTransaction
    Private strProprietario As String

    Public Sub New()
        If objConexao Is Nothing Then
            Dim objConexaoBanco As ConexaoBanco = New ConexaoBanco
            objConexao = objConexaoBanco.getConexao()
            objConexaoBanco = Nothing
        End If
    End Sub

    Private Property Conexao() As SqlConnection
        Get
            Conexao = objConexao
        End Get
        Set(ByVal Value As SqlConnection)
            objConexao = Value
        End Set
    End Property

    Private Property Transacao() As SqlTransaction
        Get
            Transacao = objTransacao
        End Get
        Set(ByVal Value As SqlTransaction)
            objTransacao = Value
        End Set
    End Property

    Public Sub iniciarTransacao(ByVal strProprietario As String)
        Try
            If Transacao Is Nothing Then
                Me.strProprietario = strProprietario
                Transacao = Me.Conexao.BeginTransaction
            End If
        Finally
        End Try
    End Sub

    Public Sub commit(ByVal strProprietario As String)
        Try
            If Me.strProprietario.Trim = strProprietario.Trim Then
                Transacao.Commit()
            End If
        Finally

        End Try

    End Sub

    Public Sub rollBack(ByVal strProprietario As String)
        Try
            If Me.strProprietario.Trim = strProprietario.Trim Then
                Transacao.Rollback()
            End If

        Finally

        End Try
    End Sub

    Public Function getConexao() As SqlConnection
        getConexao = objConexao
    End Function

    Public Function getTransacao() As SqlTransaction
        getTransacao = objTransacao
    End Function

End Class
